<?php

class ModelAccountEmail extends Model {

    public function addEmail($data) {
        if (isset($data['email']) && isset($data['name'])) {
            $email = $this->db->escape($data['name']);
            if ($this->checkEmailExist($email)) {
                return "Email exist!";
            }
            $sql = "INSERT INTO " . DB_PREFIX . "email SET email = '" . $this->db->escape($data['email']) . "', "
                    . "name = '" . $email . "', date_added = NOW()";
            $this->db->query($sql);
            return "Success!";
        } else {
            return "Error!";
        }
    }

    public function checkEmailExist($email) {
        $sql = "SELECT * FROM " . DB_PREFIX . "email WHERE email = '" . $email . "'";
        $res = $this->db->query($sql);
        if ($res->num_rows != 0) {
            return true;
        }
        return false;
    }

}

?>
